<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">-->
<title>用户编辑</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

<jsp:include page="../common/import.jsp"></jsp:include>

</head>
<body>
<!-- <div class="iframe-cot pt0" id="smIframe"> -->
       <div class="right-form mt0">
       <form class="add-form" id="editForm" method="post" action="#" onsubmit="return false;">
          <input id="userId" type="hidden" value="${user.userId}" name="userId">
		<ul class="w100 layer-form">
               <li>
                   <label class="ser-label"><em class="text-red mr5">*</em>用户名：</label>
                   <div class="form-content">
                       <input id="userName" name="userName"
								class="inputText" value="${user.userName}" type="text">
                   	   <div class="form-tips text-red" ></div>
                   </div>
               </li>
               <li>
                   <label class="ser-label"><em class="text-red mr5">*</em>登录名：</label>
                   <div class="form-content">
                      <input id="loginName" name="loginName"
								class="inputText" value="${user.loginName}" type="text"
								<c:if test="${ not empty user.userId }">readonly="readonly"</c:if>>
                   	  <div class="form-tips text-red" ></div>
                   </div>
               </li>
               <li>
                   <label class="ser-label">机构：</label>
                   <div class="form-content">
						<input id="s_unitName" name="unitName"
								class="inputText" value="${user.unitName}" type="text" placeHolder="请选择" readonly>
								<input id="s_unitId" name="unitId" type="hidden"
								value="${user.unitId}" type="text">
                   </div>
               </li>             
               <li >
                   <label class="ser-label">岗位：</label>
                   <div class="form-content">
						<input id="s_postName" name="postName"
								class="inputText" value="${user.postName}" type="text" placeHolder="请选择" readonly>
								<input id="s_postId" name="postId" type="hidden"
								value="${user.postId}" >
                   </div>
               </li>
               <li >
                   <label class="ser-label">状态：</label>
                   <div class="form-content clearfix">
                   		<input name="status" value="1"
						type="radio" <c:if test="${ '0' ne user.status }">checked</c:if>>启用
						<input name="status" value="0" type="radio"
						<c:if test="${'0' eq user.status }">checked</c:if>>停用
                   </div>
               </li>
                  
               <li class="w-per">
                   <label class="ser-label">&nbsp;</label>
                   <div class="form-content clearfix">
                       <button class="btn btn-orange" id="savebtn" onclick="save()" ><i class="fa fa-save mr5"></i>保存</button>
                       <button id="cancelBtn" class="btn btn-default" onclick="closeLayerOpen()"><i class="fa fa-reply mr5"></i>返回</button>
                   </div>
               </li>
            </ul>
    	</form>
    </div>
  <!-- </div> -->
<div id="treediv" style='top:75px;left:50px;overflow:scroll;display:none; position:absolute;width:300px;height:200px;background-color:#eeffdd; border:1px solid #BEC0BF;padding:5px;font-size:12px;'>
	<a onclick="hidetreediv();" href="#" class="link-red mr5" style="cursor:pointer;color:red;text-align:right;"><i class="fa fa-close"></i>取消</a>
	<ul id="tree" class="ztree"></ul>
</div>
<div id="treediv2" style='top:75px;left:50px;overflow:scroll;display:none; position:absolute;width:300px;height:200px;background-color:#eeffdd; border:1px solid #BEC0BF;padding:5px;font-size:12px;'>
	<a onclick="hidetreediv2();" href="#" class="link-red mr5" style="cursor:pointer;color:red;text-align:right;"><i class="fa fa-close"></i>取消</a>
	<ul id="tree2" class="ztree"></ul>
</div>

</body>
<script type="text/javascript">
function closeLayerOpen(){
	parent.layer.close(parent.layer.getFrameIndex(window.name));
}
function closeLayerOpenPage(){
	layer.close(indx);
}
//layer层的index
var indx;




	$(document).ready(function() {
		$("#s_postName").focus(function() {
          var divObj = $("#treediv");
      	var txtObj = $("#s_postName");
      	showDiv(divObj,txtObj,postsetting,"${ctx}/user/getPost");
		});
		$("#s_unitName").focus(function() {
			var divObj = $("#treediv2");
      	var txtObj = $("#s_unitName");
      	showDiv2(divObj,txtObj,unitsetting2,"${ctx}/user/getUnit");
      	
		});
	});

$("#editForm").validate({
	onkeyup : false,
	onsubmit: false,
	onfocusout: function(element){
	      $(element).valid() ;
				 },
	rules : {
		userName : {
			required : true,
			maxlength: 50,
			isContainsSpecialChar: true 
		},
		loginName : {
			required : true,
			maxlength: 50,
			isContainsSpecialChar: true 
		}
	},
	messages : {
		userName : {
			required : "请完善必填信息",
			maxlength : "请输入正确的应用群组名称",
			isContainsSpecialChar : "请输入正确的应用群组名称"
		},
		loginName : {
			required : "请完善必填信息",
			maxlength: "请输入正确的应用群组名称",
			isContainsSpecialChar: "请输入正确的应用群组名称" 
		}
	},
	errorPlacement: function(error, element) {
		 if(error){    //error存在的时候
			 $(element).next().html(error); //showMsg为你自定义的信息显示区域的id。
			
		 }                            //这里的element是录入数据的对象  
		 $(element).addClass('input-danger');
		 
	 },
	 success:function(label){
		 $(label).parent().prev().removeClass('input-danger');
		
	 }
});

	function save() {
		//校验
		if(!$("#userName").valid() || !$("#loginName").valid()){
			return false;
		}
		//保存
		$("#savebtn").attr('disabled','disabled');
		$.ajax({
			url :"${ctx}/user/save", 
			type : "post",
			data : sy.serializeObject($("#editForm")),
			dataType:"json",
			success : function(result) {
			if (result.code == "success") {
				successTip();
				var userId = $.trim($("#userId").val());
				if(userId == null || userId == ''){
					 window.parent.jumpPage(1);
				 }else{
					 window.parent.jumpPage();
				 }
				
				timeCloseFrame();
				
			} else if (result.code == "retry") {
				layer.msg(result.msg, {
					icon : 2
				});
				$("#savebtn").removeAttr('disabled');
			} else	{
				 errorTip(); 
				
				$("#savebtn").removeAttr('disabled');
			}
		} 
		});
	}

</script>
</html>